/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 2e5 + 5;

int cnt[maxn];
int a[maxn], a1[maxn], a2[maxn], ans[maxn];
bool vis[maxn];

void solve() {
  int n;
  cin >> n;
  std::fill(cnt + 1, cnt + n + 1, 0);
  std::fill(a1 + 1, a1 + n + 1, 0);
  std::fill(a2 + 1, a2 + n + 1, 0);
  std::fill(vis + 1, vis + n + 1, 0);

  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    if (cnt[i] > 2) {
      cout << "NO\n";
      return;
    }
  }
  std::priority_queue<int> pq, pq2;
  for (int i = n; i >= 1; --i) {
    if (cnt[i] == 0) {
      if (!pq.empty()) {
        ans[pq.top()] = i;
        pq.pop();
      } else {
        cout << "NO\n";
        return;
      }
    } else if (cnt[i] == 1) {
    } else {
      pq.push(i);
    }
  }
  std::fill(vis + 1, vis + n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    if (cnt[a[i]] == 2) {
      if (!vis[a[i]]) {
        a1[i] = ans[a[i]];
        a2[i] = a[i];
        vis[a[i]] = true;
      } else {
        a1[i] = a[i];
        a2[i] = ans[a[i]];
      }
    } else if (cnt[a[i]] == 1) {
      a1[i] = a2[i] = a[i];
    }
  }
  cout << "YES\n";
  for (int i = 1; i <= n; ++i) {
    cout << a1[i] << ' ';
  }
  cout << '\n';
  for (int i = 1; i <= n; ++i) {
    cout << a2[i] << ' ';
  }
  cout << '\n';
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("C. Elemental Decompress.in", "r", stdin);
  freopen("C. Elemental Decompress.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
